/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.cpnc.mm.view;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import pe.edu.pucp.cpnc.mm.bean.Tile;

/**
 *
 * @author Luis
 */
public class TileButton extends JButton {
    private Tile tile;
    
    public TileButton(){
        super();
        this.tile = null;
        setContentAreaFilled(false);
        addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt){
                selectTile();
            }
        });
    }
    
    public TileButton(Tile tile){
        super();
        this.tile = tile;
        setContentAreaFilled(false);
        addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent evt){
                selectTile();
            }
        });
    }
    
    public void selectTile(){
        MainFrame.selectedTile = tile;
        MainFrame.selObj=null;
    }
    
    @Override
    public void paintComponent(Graphics g){
        if(tile!=null)
            g.drawImage(MainFrame.rd.getSprite(tile.getType()), 0, 0, getWidth(), getHeight(),null);
        super.paintComponent(g);
        
    }
}
